/*
 * File: gov.kdrm.mygset.util.RegexUtil.java
 *
 * Copyright (c) 2009 PT. XYBASE INDONESIA,
 * All Rights Reserved.
 *
 * This software is the confidential and proprietary information
 * of PT. XYBASE INDONESIA ("Confidential Information"). You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered
 * into with PT. XYBASE INDONESIA.
 *
 * Project:	mygset2
 * Created: Jun 24, 2009 9:35:21 AM
 */
package app.rci.util;

import java.util.regex.Pattern;
import java.util.regex.Matcher;

/**
 * This class represent of Utility of Regular Expression & Collection
 *
 * <p>Revision Information:<br/><i>
 * $Date: 2010-03-29 10:36:48 +0700 (Mon, 29 Mar 2010) $<br/>
 * $Revision: 24072 $
 * $LastChangedBy: reno_natalino $
 * </i></p>
 *
 * @author Imam
 */
public abstract class RegexUtil {
    /**
     * Regular Expression Constants
     */
    public interface EXP {
        /** For email*/
		String EMAIL_REGEX = "([0-9a-zA-Z]+[-._+&amp;])*[0-9a-zA-Z]+@([-0-9a-zA-Z]+[.])+[a-zA-Z]{2,6}";
		/** For email used by Javascript*/
		String EMAIL_REGEX_JS = "^"+EMAIL_REGEX+"$";
		/** For phone and fax no.*/
		String PHONE_FAX_REGEX = "^[0-9]{2,3}-[0-9]{6,10}(-[0-9]{0,5})?$";
		/** For phone no.*/
		String PHONE_REGEX = "^[0-9]{2,3}-[0-9]{6,10}(-[0-9]{0,5})?$";
        /** For phone area no.*/
        String PHONE_AREA_REGEX = "^[0-9]{2,3}$";
        /** For phone number*/
        String PHONE_NO_REGEX = "^[0-9]{6,10}(-[0-9]{0,5})?$";
		/** For fax no.*/
		String FAX_REGEX = "^[0-9]{2,3}-[0-9]{6,10}$";
        /** For fax area no.*/
        String FAX_AREA_REGEX = "^[0-9]{2,3}$";
        /** For fax number*/
        String FAX_NO_REGEX = "^[0-9]{6,10}(-[0-9]{0,5})?$";
		/** For mobile phone no.*/
		String MOBILE_PHONE_REGEX = "^[0-9]{2,4}-[0-9]{6,10}$";
        /** For mobile phone area no.*/
        String MOBILE_AREA_REGEX = "^[0-9]{2,4}$";
        /** For mobile phone number*/
        String MOBILE_NO_REGEX = "^[0-9]{6,10}$";
		/** For GST no*/
		String GSTNO_REGEX = "^[0-9]{11}$";
		/** For NR no*/
		String NRNO_REGEX = "^[0-9]{16}$";
        /** For AR no*/
		String ARNO_REGEX = "^[0-9]{16}$";
        /** For DIN*/
		String DIN_REGEX = "^[0-9]{16}$";
        /** For NR DIN*/
		String NR_DIN_REGEX = "^[0-9]{16}$";
        /** For EXEMPTION REF NO*/
		String EXEMPTION_REFNO_REGEX = "^[0-9]{16}$";
        /** For BRANCH REF NO*/
		String SPECIALSCHEME_REFNO_REGEX = "^[0-9]{16}$";
         /** For BRANCH REF NO*/
		String BRANCHDIV_REFNO_REGEX = "^[0-9]{16}$";
		/** Only numeric number less than 10000. */
		String ONLYNO_REGEX = "^[0-9]{1,4}$";
		/** For New IC no */
		String NEWIC_REGEX = "^[0-9]{12}$";
		/** For Old IC no */
		String OLDIC_REGEX = "^[a-zA-Z0-9]{1}[0-9]{1,7}$";
		/** For passport no */
		String PASSPORT_REGEX = "^[a-zA-Z0-9]*$";
		/** For passport no */
		String INCOME_TAX_NO_REGEX = "^[a-zA-Z0-9]*$";
		/** For postcode */
		String POSTCODE_REGEX = "^[0-9]{5}$";
		/** For percentage value, from 0 to 100% */
		String POSITIVE_PERCENTAGE_REGEX = "^[0-9]{0,2}(\\.[0-9]{1,2})?|(100)(\\.[0]{1,2})?$";
		/** For currency */
		String CURENCY_REGEX = "^([0-9]{1,3},([0-9]{3},)*[0-9]{3}|[0-9]+)(\\.[0-9][0-9])?$";
		/** For numeric */
		String NUMBER_REGEX = "^([0-9])*$";
		/** For numeric */
		String ZERO_REGEX = "^[0]([0])*$";
		/** For numeric */
		String INVALID_ZERO_REGEX = "^[0]{2,}$";
		/** For date */
		String DATE_REGEX = "^(0[1-9]|[12][0-9]|3[01])[- /.](0[1-9]|1[012])[- /.](19|20)\\d\\d$";
		/** For bank account no */
		String BANKACCOUNT_REGEX = "^[0-9]{1,30}$";
		/** For town */
		String TOWN_REGEX = "([a-zA-Z0-9]+|[a-zA-Z0-9]+\\s[a-zA-Z0-9]+)";
		/** Param value */
		String PARAM_REGEX = "([0-9a-zA-Z\\s.:-/]+)";
		/** For business reg no */
		String BUSINESS_REGEX = "([0-9a-zA-Z]+[-&amp;])*[0-9a-zA-Z]+";
        /** For Alphanumeric */
        String ALPHANUMERIC = "^[\\w\\s]+$";
    }

    /**
     * Validate the string format with regular expression
     * @param valueStr The string
     * @param regex Regular expression
     * @return True if is match otherwise false
     */
    public static boolean validateStr(String valueStr, String regex){

        boolean result = false;

        if (valueStr != null) {
            // Set the email pattern string
            Pattern p = Pattern.compile(regex);
            // Match the given string with the pattern
            Matcher m = p.matcher(valueStr);
            // check whether match is found
            result = m.matches();
        }
        return result;
    }
}
